package com.devin.controller;

import com.devin.model.dto.JsonResult;
import com.devin.model.entity.User;
import com.devin.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  
 *  @author devin
 *  @date 2020-04-14 11:18
 *  @version 1.0.2
*/

@ResponseBody
@Slf4j
@Controller
public class UserApi {


    @Autowired
    private UserService userService;

    //用户登入验证
    @RequestMapping("/login")
    public JsonResult getLogin(String username, String password){


        User user = userService.getByUsername(username);
        if(user == null)
        {
            userService.create(new User(username,password));
            return new JsonResult(1,"成功注册");
        }
        else{
            if(!user.getPassword().equals(password)){
                return new JsonResult(0,"密码错误");
            }else{
                return new JsonResult(1,"登入成功");
            }
        }
    }
}
